package com.education.platform.common.util;


import com.education.platform.common.exception.ParameterException;
import org.apache.commons.lang3.StringUtils;


import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * 验证工具类
 *
 */
public class ValidatorUtils {

    private static final String MOBILE_REGEX="^[1](([3][0-9])|([4][5-9])|([5][0-3,5-9])|([6][5,6])|([7][0-8])|([8][0-9])|([9][1,8,9]))[0-9]{8}$";


    public static void isMobile(String str) {
    	if(StringUtils.isBlank(str)){
            throw new ParameterException("手机号为空");
        }
        Pattern  p = Pattern.compile(MOBILE_REGEX);
        Matcher m = p.matcher(str);
        if(!m.matches()){
            throw new ParameterException("手机号格式有误");
        }
    }
    public static boolean  mobile(String str) {
        if(StringUtils.isBlank(str)){
           return false;
        }
        Pattern  p = Pattern.compile(MOBILE_REGEX);
        Matcher m = p.matcher(str);
        if(!m.matches()){
            return false;
        }
        return true;
    }
}
